/**
 * Dear programmer:
 * When I wrote this code, only god and I knew how it worked.
 * Now, only god knows it!
 *
 * @author: lyl  Date: 2019-03-02 Time: 16:39
 *
 * 人员状态
 */

import React, {Component} from 'react';
import {
    SafeAreaView,
    View,
    ScrollView,
    TouchableOpacity,
} from 'react-native';
import {connect} from 'react-redux';
import {styles} from './PersonnelStatusScreen.Style'
import {doPersonnelStatus} from "./Actions"
import LoadingView from "../../../../component/LoadingView/LoadingView";
import ImageAndTextCellView from "./component/ImageAndTextCellView";
import Search from "./component/Search";
import {FetchStatus} from "../../../../configuration/RequestConfiguration";

class PersonnelStatusScreen extends Component {

    static navigationOptions = ({navigation}) => ({
        headerTitle: `人员状态`,
        headerRight: '',//<Search navigation={navigation}/>
    });

    // 构造
    constructor(props) {
        super(props);
    }

    componentDidMount(): void {
        let {dispatch} = this.props;
        dispatch(doPersonnelStatus());
    }

    render() {
        let {onPersonnelStatus} = this.props;
        if (onPersonnelStatus.fetchStatus === FetchStatus.Success&&typeof onPersonnelStatus["DATA"] !== "undefined") {
            return (
                <SafeAreaView style={styles.body}>
                    <ScrollView style={styles.body}>
                        {
                            onPersonnelStatus["DATA"].map((item, key) => {
                                return (
                                    <View key={'View_'+key}>
                                        <TouchableOpacity key={'TouchableOpacity_'+key} activeOpacity={0.8} onPress={() => {
                                            this.props.navigation.navigate('')
                                        }}>
                                            <ImageAndTextCellView title={item["username"]} workNum={item["atwork"]} workStatus={item["status"]}/>
                                        </TouchableOpacity>
                                    </View>
                                )
                            })
                        }
                    </ScrollView>
                </SafeAreaView>
            )
        }else{
            return <LoadingView/>
        }
    }
}

const props = state => {
  return {
      onPersonnelStatus: state.onPersonnelStatus
  };
};

export default PersonnelStatusScreen = connect(props)(PersonnelStatusScreen);